package com.example.ItPhotoAlbumCloud.utils;


import java.util.Date;

/**
 * 通用返回
 *  小仙 创建人 2023-03-12 08:36:32
 */
public class CommonResult<T> extends ToString {

    /** 成功标识 */
    protected Boolean success = true;

    /** 错误码 */
    protected String errorCode;

    /** 错误描述 */
    protected String errorMsg;

    /** 返回数据 */
    protected T data;

    /** 服务器时间 */
    protected Date serverTime;

    public CommonResult(){}


    public CommonResult(T data){
        this.data = data;
    }

    public CommonResult(String errorCode, String errorMsg){
        this.success = false;
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }


    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Date getServerTime() {
        return this.serverTime == null ? new Date() : this.serverTime;
    }

    public void setServerTime(Date serverTime) {
        this.serverTime = serverTime;
    }

    public static CommonResult convert(Object result){
        return result instanceof CommonResult ? (CommonResult) result : new CommonResult(result);
    }
}

